import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { PetSpecialSkillChangeItem } from "./skill/PetSpecialSkillChangeItem";
import { Language } from "../../../../extend/language/Language";
import { PetSpecialSkillItem } from "./skill/PetSpecialSkillItem";
import { PetSkillUpgradeOperateVo } from "./vo/PetSkillUpgradeOperateVo";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { Cache } from "../../cache/Cache";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { ObjCreate } from "../common/ObjCreate";
import { ItemConfig } from "../../resource/ItemConfig";
import { PetUtil } from "./info/PetUtil";
import { ItemInfo } from "../../resource/info/ItemInfo";
import { SkillConfig } from "../../resource/SkillConfig";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { SPetSpecialSkill } from "../../../../Message/Game/SPetSpecialSkill";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class PetSkillUpgradeChangePanel
    
    export  class PetSkillUpgradeChangePanel extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._skillItems = new Vector.<PetSpecialSkillChangeItem>();
            setSize(280, 240);
            title = Language.getString(28089);
            titleHeight = 30;
            return;
        }

        /* internal  */onClickConfirmBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=this._skillItems;
            for(loc1 of loc4) 
            {
                if (!loc1.isSelect) 
                {
                    continue;
                }
                if (loc1.type == PetSpecialSkillItem.HAS_STUDY && !loc1.isUseing) 
                {
                    loc2 = new PetSkillUpgradeOperateVo();
                    loc2.petUid = this._petInfo.uid;
                    loc2.index = this._index + 1;
                    loc2.skillId = this._curUseSpecialSkill[this._index] != this.getCurLevelId(loc1.skill.skillId) ? this.getCurLevelId(loc1.skill.skillId) : 0;
                    loc1.isSelect = false;
                    loc1.type = loc1.type;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetSkillUse, loc2));
                    break;
                }
                if (loc1.type != PetSpecialSkillItem.NO_STUDY) 
                {
                    continue;
                }
                MsgManager.showRollTipsMsg(Language.getString(28093));
            }
            return;
        }

        /* internal  */onClickCancelBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */getCurLevelId(arg1: int): int
        {
            if (this._petSpecialSkill.level == 0) 
            {
                return arg1;
            }
            return (arg1 + this._petSpecialSkill.level - 1);
        }

        public set petInfo(arg1: SPetInfo)
        {
            this._petInfo = arg1;
            return;
        }

        public set skillInfos(arg1: Array<any>)
        {
            var loc2=null;
            var loc3=0;
            this._petSpecialSkill = arg1[this._index];
            var loc1=Cache.instance.pack.backPackCache.getSpecialPetSkillBookList(ItemsUtil.isSpecialPetSkillBook);
            var loc4=0;
            var loc5=this._skillItems;
            for(loc2 of loc5) 
            {
                if ((loc3 = this._petSpecialSkill.skills.indexOf(this.getCurLevelId(loc2.skill.skillId))) != -1) 
                {
                    loc2.isUseing = this._curUseSpecialSkill[this._index] == this.getCurLevelId(loc2.skill.skillId);
                    loc2.type = PetSpecialSkillItem.HAS_STUDY;
                    continue;
                }
                if (loc1.indexOf(loc2.skill.skillId) != -1) 
                {
                    loc2.isUseing = false;
                    loc2.type = PetSpecialSkillItem.CAN_STUDY;
                    continue;
                }
                loc2.isUseing = false;
                loc2.type = PetSpecialSkillItem.NO_STUDY;
            }
            return;
        }

        public set curUseSpecialSkill(arg1: Array<any>)
        {
            this._curUseSpecialSkill = arg1;
            return;
        }

        public set index(arg1: int)
        {
            this._index = arg1;
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            var loc2=null;
            var loc7=null;
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(ObjCreate.createBg(18, 42, 244, 185, this));
            var loc1=ItemConfig.instance.getItemsByJudge(PetUtil.isSpecialPetSkillBookDraw);
            var loc3=loc1.length;
            var loc4=0;
            while (loc4 < loc3) 
            {
                loc2 = loc1[loc4] as ItemInfo;
                (loc7 = new PetSpecialSkillChangeItem()).skill = SkillConfig.instance.getInfoByName(loc2.item.effect);
                loc7.skillLevel = 0;
                loc7.type = PetSpecialSkillItem.NO_STUDY;
                loc7.onlyShowSkill();
                ObjCreate.setObjAttri(loc7, 57 + 45 * loc4 % 4, 100 + 43 * Math.floor(loc4 / 4), 32, 32, this);
                this._skillItems.push(loc7);
                ++loc4;
            }
            this._txt = ObjCreate.createGTextField(Language.getString(28090), 48, 50, 200, 40, this, GlobalStyle.setTextFormatLeading(GlobalStyle._textFormat1, 5), true);
            this._txt.multiline = true;
            this._txt.wordWrap = true;
            var loc5=ObjCreate.createGButton(Language.getString(28091), 70, 190, 49, 28, this);
            var loc6=ObjCreate.createGButton(Language.getString(28092), 165, 190, 49, 28, this);
            loc5.configEventListener(flash.events.MouseEvent.CLICK, this.onClickConfirmBtnHandler);
            loc6.configEventListener(flash.events.MouseEvent.CLICK, this.onClickCancelBtnHandler);
            pushUIToDisposeVec(loc5);
            pushUIToDisposeVec(loc6);
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            var loc1=null;
            this._txt.dispose();
            var loc2=0;
            var loc3=this._skillItems;
            for(loc1 of loc3) 
            {
                DisplayUtil.removeMe(loc1);
                loc1 = null;
            }
            this._skillItems = new Vector.<PetSpecialSkillChangeItem>();
            return;
        }

        /* internal */ /* var */_txt: GTextFiled;

        /* internal */ /* var */_index: int;

        /* internal */ /* var */_petSpecialSkill: SPetSpecialSkill;

        /* internal */ /* var */_skillItems: Vector.<PetSpecialSkillChangeItem>;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_curUseSpecialSkill: Array<any>;
    }
